<?php
require_once("../lib/DbWrapper.class.php");
session_start();
require("../libs/Smarty.class.php");
require("../libs/myUtil.class.php");
$smarty = new Smarty;
DbWrapper::dbChoice();

$id = $_POST["id"];
$nickname = $_POST["nickname"];
$mailaddress = $_POST["mailaddress"];
$password = $_POST["password"];
$admin_yn = $_POST["admin_yn"];
//input.phpから来たかどうかを判断する処理
if($_SESSION["member_edit_input_id"] != $_POST["member_edit_input_id"]){
    header("Location:http://localhost/bbs/admin/index.php");
}else{
    //同じページでの更新を防ぐ処理
    $_SESSION["member_edit_input_id"] = rand();
}

//result.phpでconfirm.phpから来たかどうか判断するための処理
$_SESSION["member_edit_confirm_id"] =rand();

$smarty->assign("id", $id);
$smarty->assign("nickname",$nickname);
$smarty->assign("mailaddress",$mailaddress);
$smarty->assign("password",$password);
$smarty->assign("admin_yn",$admin_yn);
$_SESSION["tmpnickname"] = $nickname;
$_SESSION["tmpmailaddress"] = $mailaddress;
$_SESSION["tmppassword"] = $password;
$_SESSION["tmpadmin_yn"] = $admin_yn;

$error_flg = "n";
$error_nickname_yn = "n";
$error_mailaddress_yn = "n";
$error_mailaddress_already = "n";
$error_password_yn = "n";
if($nickname == ""){
    $error_flg ="y";
    $error_nickname_yn = "y";
}
if($mailaddress == ""){
    $error_flg ="y";
    $error_mailaddress_yn = "y";
}
$sql = "SELECT count(*) FROM member
        WHERE mailaddress = \"" . $mailaddress.
        "\"AND id != \"" .$id. "\" AND delete_yn != 'y'";
$result = mysql_query($sql);
$row = mysql_fetch_row($result);
if($row[0] > 0){
    $error_flg ="y";
    $error_mailaddress_already = "y";
}
if($password == ""){
    $error_flg ="y";
    $error_password_yn = "y";
}
if($error_flg == "y"){
    $error_url = "http://localhost/bbs/admin/member_edit_input.php?id={$id}";
    if($error_nickname_yn == "y"){
        $error_url .= "&error_nickname_yn=y";
    }
    if($error_mailaddress_yn == "y"){
        $error_url .= "&error_mailaddress_yn=y";
    }
    if($error_mailaddress_already == "y"){
        $error_url .= "&error_mailaddress_already=y";
    }
    if($error_mailaddress_yn == "y"){
        $error_url .= "&error_password_yn=y";
    }

    header("Location:".$error_url);
}


$smarty->display("member_edit_confirm.tpl");